import java.io.*;
import java.net.*;
import java.util.Scanner;
import java.util.*;

public class Client {
    public static void main(String args[]) {
        String expression;
        String result;
        Socket mysocket;
        DataInputStream in=null;
        DataOutputStream out=null;
        Skey_kb k = new Skey_kb();
        System.out.println("客户端启动");
        Scanner input = new Scanner(System.in);
        MyDC evaluator = new MyDC();
        System.out.println("Enter a valid postfix expression:");
        expression = input.nextLine();
        result = evaluator.trans(expression);
        System.out.println("after trans:"+ result);
        System.out.println("enc:");



        try{
            String temp="";
            try {
                k.createKey();
                k.getByteKey();
                temp = k.enc(result);
            }
            catch(Exception e){
                System.out.println("enc is not success"+e);
            }
            System.out.println("temp:"+temp);
            mysocket=new Socket("127.0.0.1",2010);
            in=new DataInputStream(mysocket.getInputStream());
            out=new DataOutputStream(mysocket.getOutputStream());
            out.writeUTF(temp);
            String  s=in.readUTF();   //in readmessage
            System.out.println("Client get the answer:"+s);
            Thread.sleep(500);

        }
        catch(Exception e) {
            System.out.println("Server is already stoped"+e);
        }
    }
}
